#!/usr/bin/env python3
import sys
import re

class Plot:
    def __init__(self):
        self.width = 0
        self.height = 0
        self.pixels = []

    def __str__(self):
        return '\n'.join([ str(row) for row in self.pixels ])

    def higher(self, y1, y2):
        return y1 > self.height or y2 > self.height

    def wider(self, x1, x2):
        return x1 > self.width or x2 > self.width

    def resize(self, x1, y1, x2, y2):
        if self.higher(y1, y2):
            m = max(y1, y2) + 1
            for i in range(m - self.height):
                self.pixels.append([0] * self.width)
            self.height = m
        if self.wider(x1, x2):
            m = max(x1, x2) + 1
            for row in self.pixels:
                for i in range(m - self.width):
                    row.append(0)
            self.width = m

    def line(self, x1, y1, x2, y2):
        print('({}, {}) -> ({}, {})'.format(x1, y1, x2, y2))
        if (x1 != x2) and (y1 != y2):
            print('not a straight line')
            return
        # if necessary add to grid
        self.resize(x1, y1, x2, y2)
        # vertical line
        if x1 == x2:
            for i in range(min(y1, y2), max(y1, y2) + 1):
                self.pixels[i][x1] += 1
        # horizontal line
        elif y1 == y2:
            for i in range(min(x1, x2), max(x1, x2) + 1):
                self.pixels[y1][i] += 1
        print(self)

    def get_danger_points(self):
        return sum([ sum(1 if pixel > 1 else 0 for pixel in row) for row in self.pixels])

plot = Plot()
pattern = re.compile(r"^([0-9]+),([0-9]+) -> ([0-9]+),([0-9]+)$")
for line in sys.stdin:
    line = line.rstrip('\n')
    match = re.search(pattern, line)
    if match:
        plot.line(int(match.group(1)), int(match.group(2)), int(match.group(3)), int(match.group(4)))

print(plot.get_danger_points())
